package com.ling.service;

import com.ling.bean.UserDownvoteAnswer;
import com.ling.bean.UserDownvoteAnswerExample;
import com.ling.dao.UserDownvoteAnswerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserDownvoteAnswerService {
    private final UserDownvoteAnswerMapper userDownvoteAnswerMapper;

    @Autowired
    public UserDownvoteAnswerService(UserDownvoteAnswerMapper userDownvoteAnswerMapper) {
        this.userDownvoteAnswerMapper = userDownvoteAnswerMapper;
    }

    //增加记录
    public void addUserDownvoteAnswer(UserDownvoteAnswer userDownvoteAnswer) {
        userDownvoteAnswerMapper.insert(userDownvoteAnswer);
    }

    //查看是否存在记录
    public boolean existUserDownvoteAnswer(String userId,String answerId) {
        UserDownvoteAnswerExample userDownvoteAnswerExample = new UserDownvoteAnswerExample();
        userDownvoteAnswerExample.createCriteria().andUseridEqualTo(userId).andDownvoteansweridEqualTo(answerId);
        return userDownvoteAnswerMapper.countByExample(userDownvoteAnswerExample)>0;
    }
}
